//
//  RBWalletOtherChargeVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/8/3.
//

#import "RBWalletOtherChargeVC.h"
#import "UIView+RBAdd.h"
#import "UIScrollView+RBAdd.h"
#import <Masonry.h>
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "RanTool.h"
#import "RBPager.h"
#import <UINavigationController+FDFullscreenPopGesture.h>
#import "UIViewController+RBAdd.h"
#import "RBTextField.h"
#import "RBMyWalletDetailVC.h"

@interface RBWalletOtherChargeVC ()

@property(nonatomic, strong)UIScrollView *scrollView;
@property(nonatomic, strong)UIView *topView;
@property(nonatomic, strong)RBTextField *chargeAmountF;
@property(nonatomic, strong)UILabel *chargeTipL;
@property(nonatomic, strong)NSMutableArray *payWayViews;
@property(nonatomic, assign)NSInteger payWayIndex;
@property(nonatomic, strong)UILabel *noteL;

@end

@implementation RBWalletOtherChargeVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
}

#pragma mark - Private

- (void)setup
{
    self.title = @"充值";
    self.view.backgroundColor = UIColor.whiteColor;
    [self.scrollView rbSetContentWidth:kRBMainScreenWidth];
    [self.scrollView addView:self.topView withHeight:CGFLOAT_MIN width:self.topView.width top:Zoom(12) bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
    [self.scrollView addView:({
        UIView *view = UIView.new;
        UILabel *leftL = [RanTool labelWithFontSize:Zoom(16) weight:1 color:[RBThemeConfig textBlackColor] align:0 text:@"支付方式："];
        [view addSubview:leftL];
        [leftL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(Zoom(16));
            make.top.bottom.mas_equalTo(0);
        }];
        view;
    }) withHeight:CGFLOAT_MIN width:kRBMainScreenWidth top:Zoom(40) bottom:0 left:0 right:0 centerX:0];
    for(NSInteger i = 0; i < 2; i++)
    {
        [self.scrollView addView:[self payWayWithIndex:i] withHeight:Zoom(50) width:kRBMainScreenWidth top:0 bottom:0 left:0 right:0 centerX:0];
    }
    [self.scrollView addView:({
        UIView *view = UIView.new;
        UILabel *leftL = [RanTool labelWithFontSize:Zoom(16) weight:1 color:[RBThemeConfig textBlackColor] align:0 text:@"注意事项"];
        [view addSubview:leftL];
        [leftL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(Zoom(16));
            make.top.bottom.mas_equalTo(0);
        }];
        view;
    }) withHeight:CGFLOAT_MIN width:kRBMainScreenWidth top:Zoom(40) bottom:0 left:0 right:0 centerX:0];
    [self.scrollView addView:self.noteL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(18) bottom:0 left:Zoom(17) right:Zoom(17) centerX:NO];
    [self.scrollView addView:({
        UILabel *view = [RanTool labelWithFontSize:Zoom(15) weight:0 color:[UIColor whiteColor] align:1 text:@"立即充值"];
        view.backgroundColor = [UIColor colorWithHexString:@"#518CFF"];
        [view rbSetCornerRadius:Zoom(22)];
        view;
    }) withHeight:Zoom(44) width:Zoom(350) top:Zoom(130) bottom:Zoom(50) left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
    [self selectPayWayAtIndex:0];
}

- (void)selectPayWayAtIndex: (NSInteger)index
{
    self.payWayIndex = index;
    for (UIView *itemView in self.payWayViews)
    {
        UIImageView *imgView = (UIImageView *)[itemView viewWithTag:33];
        imgView.image = itemView.tag == index? [UIImage imageNamed:@"addressListDefault"]: [UIImage imageNamed:@"groupPayUnsel"];
    }
}

#pragma mark - Network

#pragma mark - Event

- (void)detailBtnTapped
{
    RBMyWalletDetailVC *vc = RBMyWalletDetailVC.new;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)payWayViewTapped: (UITapGestureRecognizer *)ges
{
    [self selectPayWayAtIndex:ges.view.tag];
}

#pragma mark - Setter

#pragma mark - Getter

- (UIScrollView *)scrollView
{
    if (!_scrollView)
    {
        self.scrollView = ({
            UIScrollView *view = UIScrollView.new;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(0);
            }];
            view;
        });
    }
    return _scrollView;
}

- (UIView *)topView
{
    if (!_topView)
    {
        self.topView = ({
            UIView *view = UIView.new;
            view.width = Zoom(350);
            view.backgroundColor = UIColor.whiteColor;
            view.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.1].CGColor;
            view.layer.shadowOffset = CGSizeMake(0,0);
            view.layer.shadowOpacity = 1;
            view.layer.shadowRadius = Zoom(8);
            view.layer.cornerRadius = Zoom(7.6);
            
            UILabel *titleL = [RanTool labelWithFontSize:Zoom(14) weight:0 color:@"#202224" align:0 text:@"充值金额"];
            [view addSubview:titleL];
            [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(Zoom(17));
                make.top.mas_equalTo(Zoom(21));
            }];
            
            UILabel *unitL = [RanTool labelWithFontSize:Zoom(15) weight:0 color:@"#121922" align:0 text:@"￥"];
            [view addSubview:unitL];
            [unitL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(titleL.mas_bottom).offset(Zoom(26));
                make.left.mas_equalTo(titleL);
            }];
            
            RBTextField *field = RBTextField.new;
            self.chargeAmountF = field;
            field.placeholder = @"请输入金额";
            field.type = RBTextFieldTypePrice;
            field.textColor = [RBThemeConfig textBlackColor];
            field.font = [UIFont systemFontOfSize:Zoom(28) weight:UIFontWeightMedium];
            [view addSubview:field];
            [field mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(Zoom(32));
                make.top.mas_equalTo(titleL.mas_bottom);
                make.height.mas_equalTo(Zoom(56));
                make.right.mas_equalTo(-Zoom(17));
            }];
            
            UIView *lineView = UIView.new;
            lineView.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
            [view addSubview:lineView];
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(0.5);
                make.left.mas_equalTo(Zoom(17));
                make.right.mas_equalTo(-Zoom(17));
                make.top.mas_equalTo(field.mas_bottom);
            }];
            
            UIView *bottomView = UIView.new;
            [view addSubview:bottomView];
            [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(Zoom(17));
                make.right.mas_equalTo(-Zoom(17));
                make.height.mas_equalTo(Zoom(48));
                make.top.mas_equalTo(lineView.mas_bottom);
                make.bottom.mas_equalTo(0);
            }];
            
            UILabel *chargeTipL = [RanTool labelWithFontSize:Zoom(13) weight:1 color:@"#F25B50" align:0 text:@"充满100元 赠送5元"];
            self.chargeTipL = chargeTipL;
            [bottomView addSubview:chargeTipL];
            [chargeTipL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.bottom.mas_equalTo(0);
            }];
            
            UILabel *detailL = [RanTool labelWithFontSize:Zoom(13) weight:1 color:@"#255DD9" align:0 text:@"余额明细"];
            [detailL rbAddTapGesWithTarget:self action:@selector(detailBtnTapped)];
            [bottomView addSubview:detailL];
            [detailL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.top.bottom.mas_equalTo(0);
            }];
            
            view;
        });
    }
    return _topView;
}

- (UIView *)payWayWithIndex: (NSInteger)index
{
    NSArray *imgs = @[
        @"walletWechat",
        @"walletAli",
    ];
    NSArray *names = @[
        @"微信",
        @"支付宝",
    ];
    UIView *view = UIView.new;
    [self.payWayViews addObject:view];
    view.tag = index;
    [view rbAddTapGesWithTarget:self action:@selector(payWayViewTapped:)];
    
    UIImageView *imgView = [UIImageView.alloc initWithImage:[UIImage imageNamed:imgs[index]]];
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    [view addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(Zoom(16));
        make.width.height.mas_equalTo(Zoom(18));
        make.centerY.mas_equalTo(0);
    }];
    
    UILabel *nameL = [RanTool labelWithFontSize:Zoom(15) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:names[index]];
    [view addSubview:nameL];
    [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imgView.mas_right).offset(Zoom(9));
        make.centerY.mas_equalTo(0);
    }];
    
    UIImageView *selImgView = UIImageView.new;
    selImgView.tag = 33;
    [view addSubview:selImgView];
    [selImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-Zoom(16));
        make.width.height.mas_equalTo(Zoom(15));
    }];
    
    return view;
}

- (NSMutableArray *)payWayViews
{
    if (!_payWayViews)
    {
        self.payWayViews = NSMutableArray.array;
    }
    return _payWayViews;
}

- (UILabel *)noteL
{
    if (!_noteL)
    {
        self.noteL = ({
            NSString *text = @"1、由于网络原因，提现申请会出现延时处理现象，请在24小时内注意查收\n2、请及时关注零钱，查询是否充值成功\n3、请及时关注余额记录中是否有余额转入\n4、可通过余额明细，查看交易详情\n5、如果充值过程中涉及任何手续费用都由用户承担";
            UILabel *textL = UILabel.new;
            textL.numberOfLines = 0;
            textL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(12)] color:[UIColor colorWithHexString:@"#9EA3A9"] string:text lineSpacing:Zoom(7)];
            }];
            textL;
        });
    }
    return _noteL;
}

@end
